<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="referrer" content="never">
    <title>作用域</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        ul {
            list-style: none;
        }
    </style>
</head>
<body>
    
    <script type="text/javascript">
        /* 
        函数作用域：词法作用域（静态作用域）指声明时所在的作用域
        作用域链：指明变量取值的标识。当前作用域 -> ... -> 全局作用域
        */

        var scope = "window";

        function logScope(){
            // console.log("a", a); // Error
            console.log(scope);
        }
        
        function fn(){
            var scope = "fn";
            var a = 10;
            logScope();
        }

        // logScope(); // window
        fn(); // 
    </script>
</body>
</html>